package com.example.spsaveqqty.attraction;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.example.spsaveqqty.R;
import com.example.spsaveqqty.map_weather;

import java.io.Serializable;
import java.util.List;

public class InformationActivity extends AppCompatActivity {

    private TextView tv_inrro;
    private TextView tv_address;
    private ImageView info_pic;
    private TextView tv_name;
    private TextView tv_score;
    private TextView tv_notice;
    private TextView tv_time;
    private TextView tv_policy;
    private TextView tv_price;
    private TextView tv_notes;
    private TextView tv_intro;
    private RelativeLayout layout_comment;
    private RelativeLayout layout_query;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_information);

        Intent i = getIntent();
        final Attraction attraction = (Attraction)i.getSerializableExtra("attraction");

        tv_notice = findViewById(R.id.tv_notice);
        String notice = attraction.getNotice();
        final String attract_name = attraction.getAttract_name();
        String[] noti=notice.split("；");
        for(String n: noti){
            tv_notice.append(n+"\n");
        }

        tv_time = findViewById(R.id.tv_time);
        String opentime = attraction.getOpentime();
        String[] ot=opentime.split("；");
        for(String o: ot){
            tv_time.append(o+"\n");
        }

        tv_policy = findViewById(R.id.tv_policy);
        String policy = attraction.getPolicy();
        String[] po=policy.split("；");
        for(String p: po){
            tv_policy.append(p+"\n");
        }

        tv_price = findViewById(R.id.tv_price);
        String price = attraction.getPrice();
        String[] pr=price.split("；");
        for(String p: pr){
            tv_price.append(p+"\n");
        }

        tv_notes = findViewById(R.id.tv_notes);
        String notes = attraction.getNotes();
        String[] no=notes.split("；");
        for(String n: no){
            tv_notes.append("• "+n+"\n");
        }

        tv_intro = findViewById(R.id.tv_intro);
        String intro = attraction.getIntroduction();
        tv_intro.setText(intro);

        tv_name = findViewById(R.id.tv_name);
        tv_name.setText(attraction.getAttract_name());

        tv_score = findViewById(R.id.tv_score);
        tv_score.setText(attraction.getScore()+"分");

        tv_inrro = findViewById(R.id.tv_inrro);
        tv_inrro.setText(attraction.getTip());


        tv_address = findViewById(R.id.tv_address);
        tv_address.setText(attraction.getAddress());
        tv_address.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                    Intent intent = new Intent(InformationActivity.this, map_weather.class);
//                    intent.putExtra("username", CheckUser.isLogin() );
                    intent.putExtra("position_name", attraction.getAddress());
                 //   InformationActivity.this.finish();
                    startActivity(intent);

            }
        });

        info_pic = findViewById(R.id.info_pic);
        Glide.with(this).load(attraction.getPic()).into(info_pic);

        layout_comment = findViewById((R.id.layout_comment));
        layout_comment.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String user = CheckUser.isLogin();
                if(user == null){
                    Toast.makeText(InformationActivity.this,"请先登录再评论哦~" ,Toast.LENGTH_SHORT).show();
                }else{
                    Intent intent = new Intent(InformationActivity.this, CommentActivity.class);
//                    intent.putExtra("username", CheckUser.isLogin() );
                    intent.putExtra("attract_name", attract_name);
                    InformationActivity.this.finish();
                    startActivity(intent);
                }
            }
        });

        layout_query = findViewById(R.id.layout_query);
        layout_query.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                AttractionDao dao = new AttractionDao(InformationActivity.this);
                List<Comment> commentList = null;
                commentList = dao.queryComment(attract_name);
//
//                for (Comment c: commentList) {
//                    Log.i("------?><--------------", c.toString());
//                }


                Intent intent = new Intent(InformationActivity.this, ShowCommentActivity.class);
                intent.putExtra("commentList", (Serializable) commentList);
                startActivity(intent);
                }
        });

    }
}
